<?php if (!defined('BASEPATH'))exit('No direct script access allowed');

class Polling extends CI_Controller
{
    public function index()
    {
        $pilihan = $this->input->post('pilihan');
        $tombol = $this->input->post('tombol');
        if($pilihan != '' && $tombol == 'Pilih')
        {
            $this->db->insert('polling', 
                    array('rate' => $pilihan,
                          'ip' => $_SERVER['REMOTE_ADDR'])
                    );
        }
        $rslt_hasil = $this->db->query('SELECT COUNT(IF(p.rate = 1, id, NULL)) AS satu, 
            COUNT(IF(p.rate = 2, id, NULL)) AS dua, 
            COUNT(IF(p.rate = 3, id, NULL)) AS tiga, 
            COUNT(IF(p.rate = 4, id, NULL)) AS empat 
            FROM polling p ORDER BY p.id ASC')->row();
        $data['sangat_bagus'] = $rslt_hasil->empat;
        $data['bagus'] = $rslt_hasil->tiga;
        $data['lumayan'] = $rslt_hasil->dua;
        $data['biasa'] = $rslt_hasil->satu;
        $this->template->home('home/v_polling', $data, "Hasil Polling");
    }
}

/* End of file polling.php */
/* Location: ./application/controllers/polling.php */